/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$(".btn-dt").click(function () {
    var groupid = $(this).data("id");
    //console.log('start : '+groupid)
    layer.confirm('是否要删除', {btn: ['确认', '取消']}, function () {
        var datastr = "cont=1&groupid=" + groupid;
        $.ajax({
            type: "post",
            url: "/../../controller/systemset/groupcontroller.php",
            data: datastr,
            success: function (e) {
                var result = eval("(" + e + ")");
                if (result.code == 0) {
                    layer.msg('操作成功', {
                        time: 2000, //2s后自动关闭
                        btn: ['OK']
                    });
                } else {
                    console.log(result.msg);
                    layer.msg('操作失败,请刷新重试', {   
                        time: 4000, //20s后自动关闭
                        btn: ['OK']
                    });
                }
            }
        });
    });
});

$(".btn-et").click(function () {
    var groupid = $(this).data("id");
    $("#groupid").val(groupid);
});

$("#submitgroup").click(function () {
    var groupid = $("#groupid").val();
    var name = $("#myname").val();
    var intro = $("#myintro").val();
    var datastr = "cont=2&groupid=" + groupid+"&name="+name+"&intro="+intro;
    $.ajax({
        type: "post",
        url: "/../../controller/systemset/groupcontroller.php",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                $("#close1").trigger("click");
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            } else {
                console.log(result.msg);
                layer.msg('操作失败,请刷新重试', {
                    time: 4000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
});

function mydeleteall(ids){
    var datastr = "cont=3&groupid="+ids;
    $.ajax({
        type: "post",
        url: "/../../controller/systemset/groupcontroller.php",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            console.log(e);
            if(result.code == 0){
                var userstr = result.ids;
                var userarr = userstr.split(',');
                $(userarr).each(function(i,n){
                    $("#userlist"+n).fadeOut();
                });
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }else{
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
            
        }
    });
}
